package sz.szsmk.citizencard.ui.newversion.fragment

import android.graphics.Color
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.annotation.Nullable
import androidx.core.widget.NestedScrollView
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.vlayout.DelegateAdapter
import com.alibaba.android.vlayout.VirtualLayoutManager
import com.alibaba.android.vlayout.layout.OnePlusNLayoutHelper
import com.gyf.immersionbar.ImmersionBar
import com.youth.banner.indicator.CircleIndicator
import kotlinx.android.synthetic.main.fragment_home.*
import kotlinx.android.synthetic.main.layout_alltip.*
import kotlinx.android.synthetic.main.layout_banner.*
import kotlinx.android.synthetic.main.layout_daybuy.*
import kotlinx.android.synthetic.main.layout_hometop.*
import kotlinx.android.synthetic.main.layout_horizontal_list.view.*
import kotlinx.android.synthetic.main.layout_recommendation.*
import kotlinx.android.synthetic.main.layout_traffic_card.*
import kotlinx.android.synthetic.main.layout_wealthandlife.*
import org.greenrobot.eventbus.EventBus
import sz.szsmk.citizencard.DaggerApplication
import sz.szsmk.citizencard.R
import sz.szsmk.citizencard.model.network.bean.request.AddNfcCardInfo
import sz.szsmk.citizencard.model.network.bean.response.*
import sz.szsmk.citizencard.model.network.bean.response.QueryAllFunctionNewRes.ClassListBean
import sz.szsmk.citizencard.model.network.clarkbean.response.AdInfo
import sz.szsmk.citizencard.model.network.clarkbean.response.AreaInfo
import sz.szsmk.citizencard.model.network.clarkbean.response.AreaInfoResponse
import sz.szsmk.citizencard.model.network.dzbean.res.MessageEvent
import sz.szsmk.citizencard.mvp.BasePresenter
import sz.szsmk.citizencard.ui.dialogs.ShowADDialog
import sz.szsmk.citizencard.ui.dzsmkfragment.AppBaseFragment
import sz.szsmk.citizencard.ui.newversion.config.Constants
import sz.szsmk.citizencard.ui.newversion.fragment.adapter.*
import sz.szsmk.citizencard.ui.newversion.fragment.presenter.HomePresenter
import sz.szsmk.citizencard.ui.newversion.fragment.view.HomeMvpView
import sz.szsmk.citizencard.util.*
import javax.inject.Inject


/**
 *  author : hyt
 *  date : 2020/7/2
 *  description :
 */
class HomeFragment :  AppBaseFragment(), HomeMvpView {


    //顶部banner
    var topBannerdatas = mutableListOf<AdInfo>()
    lateinit var topBannerAdapter: HomeTopBannerAdapter
    lateinit var tv_hello: TextView
    //nfcInfo
    var cardList =ArrayList<AddNfcCardInfo>()
    var addNfcCardInfo= AddNfcCardInfo()
    var extend : String? = ""

    //banner
    var datas = ArrayList<AdInfo>()
    lateinit var bannerAdapter : HomeBannerAdapter

    //热门推荐
    var datasRecommend = ArrayList<AdInfo>()
    lateinit var recommendAdapter :  HomeBannerRecommendAdapter

    //用户自己配置的 应用
    lateinit var homeUserAppModuleAdapter : HomeUserAppModuleAdapter

    //市民金融
    lateinit var homeFinanceAdapter :HomeFinanceAdapter

    //文化
    lateinit var onePlusNCultureLayoutHelper : OnePlusNLayoutHelper

    //旅游
    lateinit var onePlusTwoAdatper :OnePlusTwoAdapter

    //扩展模块1
    lateinit var extendModule1Adapter:HomeFinanceAdapter

    //扩展模块2
    lateinit var extendModule2Adapter :OnePlusTwoAdapter
    lateinit var onePlusNExtend2LayoutHelper : OnePlusNLayoutHelper

    //扩展模块3
    lateinit var extendModule3Adapter:HomeFinanceAdapter

    //扩展模块4
    lateinit var extendModule4Adapter :OnePlusTwoAdapter
    lateinit var onePlusNExtend3LayoutHelper : OnePlusNLayoutHelper

    //底部商品列表 每日必抢
    lateinit var bottomAdatper : HomeBottomAdapter

    //底部商品列表  可配置


    var root:View?=null


    //桂花分
    var phone : String? = null
    var LV : String? = null
    var reaName : String? = null
    var idCard : String? = null


    @Inject
    lateinit var presenter: HomePresenter

    override fun initPresenters(): Array<BasePresenter<*>>? {
        return arrayOf(presenter)
    }

    companion object{
        fun getInstance(): HomeFragment? {
            return HomeFragment()
        }
    }

    override fun onCreateView(
            inflater: LayoutInflater,
            container: ViewGroup?,
            savedInstanceState: Bundle?
    ): View? {
        if(root==null){
            root = inflater.inflate(R.layout.fragment_home, null)
            component.inject(this)
            show = ShowADDialog.getInstance(activity)
        }
        isViewOK = true
        return root
    }
    private var isViewOK = false //是否完成 View 初始化
    private var isFirst = true //是否为第一次加载
    private var show :ShowADDialog?=null
    private val kefuUrl :String ="https://tyhd.szsmk.com/dingdingkefu/index"


    override fun onResume() {
        super.onResume()

        AndroidDeviceInfo.init(activity)
        if (isViewOK && isFirst) {
            //加载数据时判断是否完成view的初始化，以及是不是第一次加载此数据
            loadDate()
            //加载第一次数据后改变状态，后续不再重复加载
            isFirst = false

            //点击跳转到关怀模式
            val ghmsjump = ghmsjump
            InitBallView.initFloatView(activity, ghmsjump)
        }

        if (isAdded){
            val arguments = arguments
            phone = arguments?.getString("phone")
            LV = arguments?.getString("LV3")
            idCard = arguments?.getString("idCard")
            reaName = arguments?.getString("reaName")
        }

        //设置仅小米手机显示nfc开卡
        if (AndroidDeviceInfo.getPhoneProducer().contains("Xiaomi")||
                AndroidDeviceInfo.getPhoneProducer().contains("Redmi")
            ||AndroidDeviceInfo.getPhoneProducer().contains("OPPO")||
            AndroidDeviceInfo.getPhoneProducer().contains("VIVO",false)
        ){
            include_traffic_card.visibility = View.VISIBLE
        }

        //广告
//        presenter.showADInfo("", "")

        requestData()

//        if(ACache.get(DaggerApplication.getIns()).getAsObject("homeCache")!=null){
//            val bean = ACache.get(DaggerApplication.getIns()).getAsObject("homeCache") as AreaInfoResponse
//
//            getAreaInfoSuccess(bean)
//        }


    }


    private var headerHeight= 0
    fun loadDate() {
        ll_chuxing.setOnClickListener { onClick(it) }
        ll_scanQR.setOnClickListener { onClick(it) }
        ll_recharge.setOnClickListener { onClick(it) }
        ll_cardList.setOnClickListener { onClick(it) }
        traffic_card_unbind.setOnClickListener { onClick(it) }
        card_recharge.setOnClickListener { onClick(it) }



        isFirst = false

        //MainActivity沉浸  手动改变view的高度  便于 滑动整体 标题栏变色
        var layoutParams = v_statusBar.layoutParams as ViewGroup.MarginLayoutParams
        layoutParams.height = ImmersionBar.getStatusBarHeight(requireActivity())
        v_statusBar.layoutParams = layoutParams

        headerHeight = ImmersionBar.getStatusBarHeight(requireActivity())

        //标题栏 渐变
        nsv_scroll.setOnScrollChangeListener(NestedScrollView.OnScrollChangeListener { v, scrollX, scrollY, oldScrollX, oldScrollY ->
            if (scrollY <= 0) { //未滑动
                rl_topBar.setBackgroundColor(Color.argb(0, 33, 132, 250))
            } else if (scrollY in 1..headerHeight) { //滑动过程中 并且在mHeight之内
                val scale: Float = scrollY.toFloat() / headerHeight
                val alpha = 255 * scale
                rl_topBar.setBackgroundColor(Color.argb(alpha.toInt(), 33, 132, 250))
            } else { //超过mHeight
                rl_topBar.setBackgroundColor(Color.argb(255, 33, 132, 250))
            }
        })

        //设置下拉刷新 圆圈的 启示位置
        srl_refresh.setProgressViewOffset(false, 210, 270)

        srl_refresh.setColorSchemeResources(R.color.color_2184FA)
        srl_refresh.setOnRefreshListener {
            //请求数据
            requestData()
            
        }

        //topBanner 初始化
        bv_topBanner.apply{
            topBannerAdapter = HomeTopBannerAdapter(context, topBannerdatas)
            adapter = topBannerAdapter
        }

        //banner 初始化
        bvp_banner.apply {
            //生命周期  绑定生命周期  会导致 轮播不正常
//            addBannerLifecycleObserver(this@HomeFragment)
            //指示器
            indicator =  CircleIndicator(view?.context)
            //设置圆角
            setBannerRound(8f)
            bannerAdapter = HomeBannerAdapter(context, datas)
            adapter = bannerAdapter
        }

        //热门推荐
        bvp_recommendation.apply {
            indicator =  CircleIndicator(view?.context)
            setBannerRound(16f)
            recommendAdapter = HomeBannerRecommendAdapter(context, datasRecommend)
            adapter = recommendAdapter
        }


        //初始化 用户配置应用
        homeUserAppModuleAdapter = HomeUserAppModuleAdapter(context)
        rv_userapp.layoutManager = GridLayoutManager(context, 5)
        rv_userapp.adapter = homeUserAppModuleAdapter
        homeUserAppModuleAdapter.moreInterface = object:HomeUserAppModuleAdapter.MoreInterface{
            override fun onClick(view: View?, position: Int) {
                if (ACache.get(DaggerApplication.getIns()).getAsString("access_token") != null) {
                    EventBus.getDefault().post(MessageEvent(MessageEvent.TO_GOVER))
                } else {
                    JumpUtils.jump(activity, "login", 0)
                }
            }
        }

        homeUserAppModuleAdapter.baseInterface = object:HomeUserAppModuleAdapter.BaseInterface{
            override fun onClick(view: View?, url: String?, syslabl: String?, need_header: Int, s: String?, bean: ClassListBean.FunctionListBean?) {

                if (ButtonUtils.isFastClick()) {
                    when (url) {
                        "proto:fund" -> {
                            val message = MessageEvent(MessageEvent.CODE_GJJ_GHF_SB)
                            message.data = "gjj"
                            EventBus.getDefault().post(message)
                        }
                        "proto:social" -> {
                            val message = MessageEvent(MessageEvent.CODE_GJJ_GHF_SB)
                            message.data = "sb"
                            EventBus.getDefault().post(message)
                        }
                        "proto:osmanthus" -> {
                            val message = MessageEvent(MessageEvent.CODE_GJJ_GHF_SB)
                            message.data = "ghf"
                            EventBus.getDefault().post(message)
                        }
                        "proto:finance" -> {
                            val message = MessageEvent(MessageEvent.CODE_OPENNG)
                            EventBus.getDefault().post(message)
                        }
                        else->{
                            if (bean?.function_name.equals("桂花分")){
                                if (LV!!.equals(1.0)){
                                    presenter.accountExist(LV,idCard,phone,reaName)
                                }
                            }else {
                                JumpThirdView.baseToJumpView(activity, url, syslabl, need_header, "")
                            }


                        }
                    }

                }
            }
        }

        //初始化 市民金融
        homeFinanceAdapter = HomeFinanceAdapter(context)
        rv_finance.layoutManager = GridLayoutManager(context, 3)
        rv_finance.addItemDecoration(SpaceItemDecoration(10))
        rv_finance.adapter = homeFinanceAdapter

        //旅游
        val virtualLayoutManager = VirtualLayoutManager(requireContext())
        val delegateAdapter = DelegateAdapter(virtualLayoutManager, true)
        val adapters = mutableListOf<DelegateAdapter.Adapter<*>>()
        onePlusNCultureLayoutHelper = OnePlusNLayoutHelper()
        onePlusTwoAdatper = OnePlusTwoAdapter(requireContext(), onePlusNCultureLayoutHelper)
        adapters.add(onePlusTwoAdatper)
        delegateAdapter.addAdapters(adapters)
        rv_cultureTour.layoutManager = virtualLayoutManager
        rv_cultureTour.adapter = delegateAdapter

        //扩展模块1
        extendModule1Adapter = HomeFinanceAdapter(context)
        include_extendModule1.rv_extendModule.layoutManager = GridLayoutManager(context, 3)
        include_extendModule1.rv_extendModule.addItemDecoration(SpaceItemDecoration(10))
        include_extendModule1.rv_extendModule.adapter = extendModule1Adapter

        //扩展模块2
        val virtualLayoutManager1 = VirtualLayoutManager(requireContext())
        val delegateAdapter1 = DelegateAdapter(virtualLayoutManager1, true)
        val adapters1 = mutableListOf<DelegateAdapter.Adapter<*>>()
        onePlusNExtend2LayoutHelper = OnePlusNLayoutHelper()
        extendModule2Adapter = OnePlusTwoAdapter(requireContext(), onePlusNExtend2LayoutHelper)
        adapters1.add(extendModule2Adapter)
        delegateAdapter1.addAdapters(adapters1)
        include_extendModule2.rv_extendModule.layoutManager = virtualLayoutManager1
        include_extendModule2.rv_extendModule.adapter = delegateAdapter1

        //扩展模块3
        extendModule3Adapter = HomeFinanceAdapter(context)
        include_extendModule3.rv_extendModule.layoutManager = GridLayoutManager(context, 3)
        include_extendModule3.rv_extendModule.addItemDecoration(SpaceItemDecoration(10))
        include_extendModule3.rv_extendModule.adapter = extendModule3Adapter

        //扩展模块4
        val virtualLayoutManager2 = VirtualLayoutManager(requireContext())
        val delegateAdapter2 = DelegateAdapter(virtualLayoutManager2, true)
        val adapters2 = mutableListOf<DelegateAdapter.Adapter<*>>()
        onePlusNExtend3LayoutHelper = OnePlusNLayoutHelper()
        extendModule4Adapter = OnePlusTwoAdapter(requireContext(), onePlusNExtend3LayoutHelper)
        adapters2.add(extendModule4Adapter)
        delegateAdapter2.addAdapters(adapters2)
        include_extendModule4.rv_extendModule.layoutManager = virtualLayoutManager2
        include_extendModule4.rv_extendModule.adapter = delegateAdapter2


        //初始化 底部recyclerview
        bottomAdatper = HomeBottomAdapter(context)
        rv_dayBuy.layoutManager = GridLayoutManager(context, 2)
        rv_dayBuy.addItemDecoration(SpaceItemDecoration(10))
        rv_dayBuy.adapter = bottomAdatper



        //搜索
        cv_search.setOnClickListener {
            JumpUtils.jump(requireContext(), "SearchHotActivity", 0)
        }

        //天气
        iv_weather.setOnClickListener {
            JumpUtils.jump(requireContext(), "weath", 0)
        }

        //消息
        rl_message.setOnClickListener {
            JumpUtils.jump(requireContext(), "HomeNews", 1)
        }

        //消息 数字 默认不显示
        tv_number.visibility = View.GONE

    }

    private fun requestData(){
        var access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token")
        if (access_token != null) {
            //请求 拼接字符串
            presenter.getGetOrderId()
            presenter.getMessageNumber()
            presenter.queryUserCard("3");
            presenter.queryUserApp()
            presenter.getOpenID("HUIMIN")

            //获取公交码是否开通
            presenter.openID(access_token)
        }
        //首页模块数据
        presenter.queryAreaInfo()
        presenter.queryNoticeInfo()
        presenter.getWeather()
    }

    fun onClick(view: View){
        when (view.id) {
            //点击出行
            R.id.ll_chuxing -> JumpUtils.jump(requireContext(), "tripPlan", 1)
            //扫码
            R.id.ll_scanQR ->{
                //直接进入 扫码界面 跳过手势
                val bundle = Bundle()
//                JumpUtils.jump(requireContext(), Constants.QRCODEACTIVITY ,1 )
                JumpUtils.jump(requireContext(), Constants.SCANQRCODECHECKACTIVITY, 1)
            }
            //充值
            R.id.ll_recharge -> JumpUtils.jump(requireContext(), "rechargeActivity", 1)
            //点击卡包
            R.id.ll_cardList -> JumpUtils.jump(requireContext(), "cardListActivity", 1)
            //绑定交通一卡通
            R.id.traffic_card_unbind -> {}
            //交通一卡通充值
            R.id.card_recharge -> {}
        }
    }

    override fun getTopTitle() = null

    override fun getAreaInfoSuccess(response: AreaInfoResponse) {

//        ACache.get(DaggerApplication.getIns()).put("homeCache", response)

        srl_refresh.isRefreshing = false
        for(areaBean in response.areaInfoVoList){
            when(areaBean.resource_area_id){
                "200" -> {
                    //首页头部 背景
                    homeTopBackground(areaBean)
                }
                "201" -> {
                    //首页banner
                    homeBanner(areaBean)
                }
                "202" -> {
                    //热门推荐
                    homeRecommend(areaBean)
                }
                "203" -> {
                    //市民金融
                    homeCitizenFinance(areaBean)
                }
                "204" -> {
                    //文化旅游
                    homeCultureTour(areaBean)
                }
                "205" -> {
                    //每日必抢
                    homeDayBuy(areaBean)
                }
                "212" -> {
                    //扩展模块1
                    extendModule1(areaBean)
                }
                "213" -> {
                    //扩展模块2
                    extendModule2(areaBean)
                }
                "214" -> {
                    //扩展模块3
                    extendModule3(areaBean)
                }
                "215" -> {
                    //扩展模块4
                    extendModule4(areaBean)
                }
            }
        }
    }

    private fun extendModule4(areaBean: AreaInfo?) {
        if(areaBean?.adInfoVoList?.isNotEmpty()!!){
            //标题
            include_extendModule4.tv_extendModuleTitle.text = areaBean.resource_area_name
            //副标题
            include_extendModule4.tv_extendModuleSubTitle.visibility = View.GONE
            if(!TextUtils.isEmpty(areaBean.resource_sub_title)){
                include_extendModule4.tv_extendModuleSubTitle.text = areaBean.resource_sub_title
                include_extendModule4.tv_extendModuleSubTitle.setOnClickListener {
                    JumpThirdView.baseToJumpView(requireContext(), areaBean.title_url, areaBean.sys_label, 0, "")
                }
                include_extendModule4.tv_extendModuleSubTitle.visibility = View.VISIBLE
            }

            extendModule4Adapter.addDatas(areaBean.adInfoVoList)
        }else{
            include_extendModule4.visibility = View.GONE
        }
    }


    //扩展模块3
    private fun extendModule3(areaBean: AreaInfo?) {
        if(areaBean?.adInfoVoList?.isNotEmpty()!!){
            //标题
            include_extendModule3.tv_extendModuleTitle.text = areaBean.resource_area_name
            //副标题
            include_extendModule3.tv_extendModuleSubTitle.visibility = View.GONE
            if(!TextUtils.isEmpty(areaBean.resource_sub_title)){
                include_extendModule3.tv_extendModuleSubTitle.text = areaBean.resource_sub_title
                include_extendModule3.tv_extendModuleSubTitle.setOnClickListener {
                    JumpThirdView.baseToJumpView(requireContext(), areaBean.title_url, areaBean.sys_label, 0, "")
                }
                include_extendModule3.tv_extendModuleSubTitle.visibility = View.VISIBLE
            }

            //数据
            extendModule3Adapter.addDatas(areaBean.adInfoVoList)
        }else{
            include_extendModule3.visibility = View.GONE
        }
    }

    //扩展模块2
    private fun extendModule2(areaBean: AreaInfo?) {
        if(areaBean?.adInfoVoList?.isNotEmpty()!!){
            //标题
            include_extendModule2.tv_extendModuleTitle.text = areaBean.resource_area_name
            //副标题
            include_extendModule2.tv_extendModuleSubTitle.visibility = View.GONE
            if(!TextUtils.isEmpty(areaBean.resource_sub_title)){
                include_extendModule2.tv_extendModuleSubTitle.text = areaBean.resource_sub_title
                include_extendModule2.tv_extendModuleSubTitle.setOnClickListener {
                    JumpThirdView.baseToJumpView(requireContext(), areaBean.title_url, areaBean.sys_label, 0, "")
                }
                include_extendModule2.tv_extendModuleSubTitle.visibility = View.VISIBLE
            }

            extendModule2Adapter.addDatas(areaBean.adInfoVoList)
        }else{
            include_extendModule2.visibility = View.GONE
        }
    }

    //扩展模块1
    private fun extendModule1(areaBean: AreaInfo?) {
        if(areaBean?.adInfoVoList?.isNotEmpty()!!){
            //标题
            include_extendModule1.tv_extendModuleTitle.text = areaBean.resource_area_name
            //副标题
            include_extendModule1.tv_extendModuleSubTitle.visibility = View.GONE
            if(!TextUtils.isEmpty(areaBean.resource_sub_title)){
                include_extendModule1.tv_extendModuleSubTitle.text = areaBean.resource_sub_title
                include_extendModule1.tv_extendModuleSubTitle.setOnClickListener {
                    JumpThirdView.baseToJumpView(requireContext(), areaBean.title_url, areaBean.sys_label, 0, "")
                }
                include_extendModule1.tv_extendModuleSubTitle.visibility = View.VISIBLE
            }

            //数据
            extendModule1Adapter.addDatas(areaBean.adInfoVoList)
        }else{
            include_extendModule1.visibility = View.GONE
        }
    }

    override fun getNoticeInfoSuccess(response: QueryInterductionAreaRes) {
        //公告
        if(response?.interdution_list?.isNotEmpty()!!){
            vf_notices.removeAllViews()
            addVf_notices(response.interdution_list)
        }else{
            include_notice.visibility = View.GONE
        }
    }

    //用户设置的 应用
    override fun getUserAppSuccess(response: QueryAllFunctionNewRes) {
        if(response?.class_list?.isNotEmpty()!!){
            if(response?.class_list[0].function_list?.isNotEmpty()!!){
                var tempList = response?.class_list[0].function_list
                val bean = ClassListBean.FunctionListBean()
                bean.function_name = "全部"
                bean.icon_url = "1"
                tempList.add(bean)

                homeUserAppModuleAdapter.addData(tempList)
            }
        }
    }

    //天气
    override fun getWeatherSuccess(response: HomeWeathRes) {
        tv_temperature.text = "${response.temperature}℃\n空气 ${response.airQuantity}"
        WeathUtils.setWeath(iv_weather, response.weather)
    }

    //首页消息数量
    override fun getMessageNumberSuccess(response: NoticeMainres) {
        if(response.unReadTotal <= 0){
            tv_number.visibility = View.GONE
        }else if(response.unReadTotal > 100){
            tv_number.visibility = View.VISIBLE
            tv_number.text = "99+"
        }else{
            tv_number.visibility = View.VISIBLE
            tv_number.text = response.unReadTotal.toString()
        }
    }

    //添加公告 View
    private fun addVf_notices(interdutionList: List<QueryInterductionAreaRes.InterdutionListBean>) {
        for(noticesBean in interdutionList){
            val view: View = LayoutInflater.from(context).inflate(R.layout.layout_home_notice_txt, null)
            view.findViewById<TextView>(R.id.tv_tip).text = noticesBean.content
            view.setOnClickListener {
                JumpThirdView.baseToJumpView(requireContext(), noticesBean.link_url, noticesBean.sys_label, noticesBean.need_header.toInt(), "")
            }
            vf_notices.addView(view)
        }

        if(interdutionList.size==1){
            vf_notices.stopFlipping()
        }
    }

    //每日必抢
    private fun homeDayBuy(areaBean: AreaInfo?) {
        if(areaBean?.adInfoVoList?.isNotEmpty()!!){
            tv_dayBuyTitle.text = areaBean.resource_area_name
            tv_dayBuyMore.text = areaBean.resource_sub_title
            bottomAdatper.addDatas(areaBean.adInfoVoList)

            tv_dayBuyMore.setOnClickListener {
                JumpThirdView.baseToJumpView(requireContext(), areaBean.title_url, areaBean.sys_label, areaBean.need_header, "")
            }
        }else{
            include_daybuy.visibility = View.GONE
        }
    }

    //文化旅游
    private fun homeCultureTour(areaBean: AreaInfo?) {

        if(areaBean?.adInfoVoList?.isNotEmpty()!!){
            //标题
            tv_ctTitle2.text = areaBean.resource_area_name
            //右边 文字
            tv_ctSubTitle.visibility = View.GONE
            if(!TextUtils.isEmpty(areaBean.resource_sub_title)){
                tv_ctSubTitle.text = areaBean.resource_sub_title
                tv_ctSubTitle.visibility = View.VISIBLE
                tv_ctTitle2.setOnClickListener {

                    JumpThirdView.baseToJumpView(requireContext(), areaBean.title_url, areaBean.sys_label, areaBean.need_header, "")
                }
            }

            onePlusTwoAdatper.addDatas(areaBean.adInfoVoList)

        }else{
            cv_cultureTour.visibility = View.GONE
        }
    }

    //市民金融
    private fun homeCitizenFinance(areaBean: AreaInfo?) {
        if(areaBean?.adInfoVoList?.isNotEmpty()!!){
            //标题
            tv_financeTitle.text = areaBean.resource_area_name
            tv_citizenFinanceSubTitle.text = areaBean.resource_sub_title
            tv_citizenFinanceSubTitle.setOnClickListener {
                JumpThirdView.baseToJumpView(requireContext(), areaBean.title_url, areaBean.sys_label, areaBean.need_header, "")
            }

            homeFinanceAdapter.addDatas(areaBean.adInfoVoList)

        }else{
            cv_citizenfinance.visibility = View.GONE
        }
    }

    //热门推荐
    private fun homeRecommend(areaBean: AreaInfo?) {
        if(areaBean?.adInfoVoList?.isNotEmpty()!!){
            recommendAdapter.setDatas(areaBean.adInfoVoList)
            recommendAdapter.notifyDataSetChanged()

            tv_recommend.text = areaBean.resource_area_name

            tv_recommendSubtitle.visibility = View.GONE
            if(!TextUtils.isEmpty(areaBean.resource_sub_title)){
                tv_recommendSubtitle.text = areaBean.resource_sub_title
                tv_recommendSubtitle.visibility = View.VISIBLE
            }


            tv_recommendSubtitle.setOnClickListener {
                JumpThirdView.baseToJumpView(requireContext(), areaBean.title_url, areaBean.sys_label, areaBean.need_header, "")
            }
        }else{
            include_recommendation.visibility = View.GONE
        }
    }

    //头部背景
    private fun homeTopBackground(areaBean: AreaInfo?) {
        if(areaBean?.adInfoVoList?.isNotEmpty()!!){
            topBannerAdapter.setDatas(areaBean.adInfoVoList)
            topBannerAdapter.notifyDataSetChanged()
        }else{
//            iv_imgBg.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.color_2184FA))
        }
    }

    //首页banner
    private fun homeBanner(areaBean: AreaInfo?){
        if (areaBean?.adInfoVoList?.isNotEmpty()!!) {
            bannerAdapter.setDatas(areaBean.adInfoVoList)
            bannerAdapter.notifyDataSetChanged()
        } else {
            include_banner.visibility = View.GONE
        }
    }

    override fun onFail(baseBean: BaseBean) {
        srl_refresh.isRefreshing = false
    }

    override fun getBindTrafficCardSuccess(element: QueryUserCardRes.DataBean) {

        layout_traffic_unbind.visibility = View.GONE
        layout_traffic_bind.visibility = View.VISIBLE







    }

    override fun getBindTrafficCardFail(baseBean: BaseBean?) {
        layout_traffic_unbind.visibility = View.VISIBLE
        layout_traffic_bind.visibility = View.GONE
    }

    override fun saveNfcCardSuccess(baseBean: BaseBean?) {
    }

    override fun saveNfcCardFail(baseBean: BaseBean?) {
    }

    override fun getOpenIDSuccess(getopenidres: GetOpenIDRes?) {
        if (getopenidres != null) {
            extend=getopenidres.extend
            recommendAdapter.setData(ACache.get(DaggerApplication.getIns()).getAsString("access_token"))
            recommendAdapter.notifyDataSetChanged()
            topBannerAdapter.setData(ACache.get(DaggerApplication.getIns()).getAsString("access_token"))
            topBannerAdapter.notifyDataSetChanged()

        }
    }

    override fun getShowADSuccess(showADRes: ShowADRes?) {
        if (showADRes != null) {
           // show!!.show(activity,showADRes.page_ad_list[0].resource_url,showADRes.page_ad_list[0].link_url)
        }
    }

    override fun accountExist(response: AccountExistRes) {
        TODO("Not yet implemented")
    }





}